字串是由字元所組成的集合,可以用雙引號或單引號來表示
而可以利用" + " 來組合兩段字串 ; 利用" * "來複製字串
name_A = "Lemon\n"
birth_B = "20010517"
print (name_A + birth_B)
print (name_A * 2)
也可使用 len()來顯示字串長度、max()及min()來顯示字串的大小值
a = "今天星期五"
print(len(a))
蠻有趣的是,Python還可以Slice(切分)字串
以[from_index:to_index]呈現,而from_index是包含在內,反之to_index是不包含在內
(超.....級.....酷.....><)
假如你想為你的字串所跳行,很簡單,你只要在後面加上 "\n"就可以了
nums = "1,2,3,4,5\n"
print(nums)
print(HelloWorld)
還有一些常用的方法就不一一贅述...總之這些方法都能很好且快速的整理一堆雜亂的字串
information: "PrACtIcE+mAKES+PErfECt.\n"
str = "PrACtIcE mAKES PErfECt."
str.capitalize()
#%%
str = "PrACtIcE mAKES PErfECt."
str.upper()
#%%
str = "PrACtIcE mAKES PErfECt."
str.lower()
#%%
str = "PrACtIcE mAKES PErfECt."
str.swapcase()
#%%
str = "PrACtIcE mAKES PErfECt."
str.title()